/**********************************************************
 *
 *  Copyright (c) 2003  SeikoEpson Inc
 *  All Rights Reserved
 *
 *  File name :f_atan.c
 *  Function  :
 *        f_atan function returns arctangent arctan( tan^-1, not 
 *               1/tan ) value.
 *        This file is copied from math.lib of 
 *                  CC33 tool(CC33v40.exe + CCPA45.exe, 
 *                  math of ansilib33v25 )
 *
 *  original file's Revision  :
 *      2000/02/10    first release                 M.Igarashi
 *  Revision  :
 *      2003/ 3/14    IrumaSoft M.Takeishi   1.st design
 *
 **********************************************************/
#include <f_math.h>
#include <f_smcvals.h>

extern float f__atan(float);

// ARGORITHM
// 1.if x > 0, use arctan x = pai/2 - arctan 1/x = _atan(x)
//   if x <=0, arctan x = -_atan(-x)
//

//  the architecture of single floating point
//
//   0 1          23 22            32bit
//   -----------------------------------
//  | |   exponent  |  fraction         |
//   -----------------------------------
//  |               |                   |
//  |      8bits          23 bits       |
//  |            lower word             |
//
//         bit   31         sign bit         (  1 bit  )
//             23 - 30      exponent part    (  8 bits )
//              0 - 22      fraction part    ( 23 bits )
//
//


float f_atan (float sfX) {

	float sfX2,sfRet;
	long lX;

	F_CLR_SIGN( sfX2, sfX );	// clear sign
	F_GETW(lX,sfX);				// get low

	sfRet = f__atan(sfX2);
	
	if((lX&0x80000000) !=0){	//check arg
		sfRet = -sfRet;
	}

	return sfRet;
}
